<?php

/**
 * Description of LineaDALC
 *
 * @author Lokerfy
 */
class LineaDALC {

    function __construct() {
        require_once 'BD.php';
        require_once '../class/PSN.BL.BE/LineaBE.php';
        require_once '../class/PSN.FL/GUID.php';
    }

    function LineaRegistrar($pobjLineaBE) {

        $objLineaBE = new LineaBE();
        $objLineaBE = $pobjLineaBE;

        $objDB = new DB();
        $objDB->Conexion();
        $query = "INSERT INTO 
                linea
                (
                LineaID,
                NombreLinea
                )
                VALUES
                (
                 '" . $objLineaBE->getLineaID() . "',
                 '" . $objLineaBE->getNombreLinea() . "'
                )";
        $result = mysql_query($query);
        mysql_close();
        if (!$result)
            return false;
        else
            return true;
    }

    function LineaActualizar($pobjLineaBE) {
        $objLineaBE = new LineaBE();
        $objLineaBE = $pobjLineaBE;

        $objDB = new DB();
        $objDB->Conexion();
        $query = "UPDATE 
                linea
                SET
                LineaID='" . $objLineaBE->getLineaID() . "',
                NombreLinea='" . $objLineaBE->getNombreLinea() . "'
                WHERE
                LineaID='" . $objLineaBE->getLineaID() . "'";
        $result = mysql_query($query);
        mysql_close();
        if (!$result)
            return false;
        else
            return true;
    }

    function LineaListar() {
        $objDB = new DB();
        $objDB->Conexion();
        $query = "SELECT 
                    LineaID,
                    NombreLinea
                FROM 
                    linea";

        $result = mysql_query($query);

        $listLineaBE = array();

        $count = mysql_num_rows($result);

        for ($i = 0; $i < $count; $i++) {
            $row = mysql_fetch_array($result);

            $objLineaBE = new LineaBE();
            $objLineaBE->setLineaID($row["LineaID"]);
            $objLineaBE->setNombreLinea($row["NombreLinea"]);

            $listLineaBE[$i] = $objLineaBE;
        }

        mysql_close();

        return $listLineaBE;
    }
    function LineaListarPorPagina($Pagina){
        $objDB=new DB();
        $objDB->Conexion();
        $query="SELECT 
                    LineaID,
                    NombreLinea
                FROM 
                    linea ".$Pagina;
        
        $result=mysql_query($query);
        
        $listLineaBE=array();
    
        $count=mysql_num_rows($result);
        
        for($i=0;$i<$count;$i++)
        {
           $row=mysql_fetch_array($result);
           
           $objLineaBE= new LineaBE();
           $objLineaBE->setLineaID($row["LineaID"]);
           $objLineaBE->setNombreLinea($row["NombreLinea"]);
           
           $listLineaBE[$i]=$objLineaBE;
        }
        
        mysql_close();
        
        return $listLineaBE;
    }
    function LineaObtener($LineaID){
        $objDB=new DB();
        $objDB->Conexion();
        $query = "SELECT 
                    LineaID,
                    NombreLinea
                FROM 
                    linea
                WHERE 
                    LineaID='$LineaID'";

        $result = mysql_query($query);

        $count = mysql_num_rows($result);

        $objLineaBE = null;

        for ($i = 0; $i < $count; $i++) {
            $row = mysql_fetch_array($result);

            $objLineaBE = new LineaBE();
            $objLineaBE->setLineaID($row["LineaID"]);
            $objLineaBE->setNombreLinea($row["NombreLinea"]);
        }

        mysql_close();

        return $objLineaBE;
    }

    function LineaEliminar($LineaID) {
        $objDB = new DB();
        $objDB->Conexion();
        $query = "DELETE
                FROM
                    linea
                WHERE 
                    LineaID='" . $LineaID . "'";

        $result = mysql_query($query);
        mysql_close();
        if (!$result)
            return false;
        else
            return true;
    }

}

?>
